package listbyorder.access001_100.test75;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/4 9:07
 */
public class Solution1 {

    // 荷兰国旗问题，快排思想
    public void sortColors(int[] nums) {
        if (nums == null || nums.length < 2) return;
        int len = nums.length;
        int less = -1;
        int more = len;
        int index = 0;
        while (index < more) {
            if (nums[index] < 1) {
                swap(nums, ++less, index++);
            } else if (nums[index] > 1) {
                swap(nums, --more, index);
            } else {
                index++;
            }
        }
    }

    private void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
